//
//  MYMainViewController.swift
//  sinaWeibo
//
//  Created by 于 on 16/8/8.
//  Copyright © 2016年 于. All rights reserved.
//

import UIKit

class MYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
      //加载子控制器
      addChildVC()
        
  
    }
    
    
    func addChildVC (){
    
        let myTabBar = MYTabBar()
        
        myTabBar.composeBtn = {
        
        print("点击了加号按钮")
        }
        
        setValue(myTabBar, forKey: "tabBar")
        
        addChildViewController(MYHomeController(), title: "首页", imaName: "tabbar_home")
        
        addChildViewController(MYMessageController(), title: "信息", imaName: "tabbar_message_center")
        
        addChildViewController(MYDiscoverController(), title: "发现", imaName: "tabbar_discover")
        
        addChildViewController(MYProfileController(), title: "我的", imaName: "tabbar_profile")
        
    
    }
    
    
     // MARK: 重载tabBar加载子控制器方法
   
     func addChildViewController(childController: UIViewController, title: String, imaName: String) {
        
       childController.title = title
        //设置图片
        childController.tabBarItem.image = UIImage(named: imaName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imaName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        //设置文字
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(13)], forState: .Normal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
    }

    

}
